package org.mozhu.mboot.core.config;


import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class SimpleConfiguration implements Configuration {

    private Map<String, String> configurations = new HashMap<>();

    public SimpleConfiguration() {
    }

    public SimpleConfiguration(Map<String, String> configurations) {
        this.configurations = configurations;
    }

    public SimpleConfiguration(Properties properties) {
        Set<String> propertyNames = properties.stringPropertyNames();
        for (String propertyName : propertyNames) {
            configurations.put(propertyName, properties.getProperty(propertyName));
        }
    }


    @Override
    public String getProperty(String name, String defaultValue) {
        return configurations.getOrDefault(name, defaultValue);
    }

    @Override
    public String getProperty(String name) {
        return configurations.get(name);
    }

    @Override
    public void setProperty(String name, String value) {
        configurations.put(name, value);
    }

    @Override
    public Map<String, String> getProperties() {
        return new HashMap<>(configurations);
    }
}
